{% extends 'app01/home.html' %}

{% block left %}
    {% load my_tag %} <!--加载inclusion_tag函数-->
    {% bote_left request %}
{% endblock %}

{% block right %}
    {% load my_tag %} <!--加载inclusion_tag函数-->
    {% bote_right request %}
{% endblock %}

{% block center_content %}
    <!--页面的内容开始-->
    <div class="text-center">
        <h3>用户笔记</h3>
    </div>

    <div>
        {% for page in c_page %}
            <div class="media">
                <div class="media-left">
                    <a href="#">
                        <img class="media-object img-circle" height="64" src="/media/{{ page.userinfo.avatar }}/"
                             alt="...">
                    </a>
                </div>
                <div class="media-body">
                    <h4 class="media-heading" style="color: #12493e">
                        <a href="/app01/preview_file?file_id={{ page.pk }}&url={{ request.get_full_path }}"
                           target="_blank">
                            {{ page.name }} </a>
                    </h4>
                    <p> {{ page.desc }}</p>
                    <div class="pull-right">

                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="#">下载数 </a>
                        <span class="badge">{{ page.number }}</span>&nbsp;&nbsp;&nbsp;
                        <a href="/app01/download/file?name={{ page.filename }}&file_id={{ page.pk }}"
                           class="down_file_class btn" file_user="{{ page.userinfo.username }}">下载文件 <span
                                class="glyphicon glyphicon-download-alt"></span></a>

                    </div>
                    <div class="pull-left" style="color: #004d88">
                        <a href="/app01/site/{{ page.userinfo.username }}">上传者:{{ page.userinfo.username }}</a>&nbsp;&nbsp;
                        &nbsp;&nbsp;
                        {{ page.create_time }}

                    </div>
                </div>
            </div>
            <hr>
        {% endfor %}
    </div>

    <!--页面的内容结束-->

    {# 分页显示 #}
    <div class="pager">
        <nav aria-label="Page navigation">
            <ul class="pagination">
                {{ page_html }}
            </ul>
        </nav>
    </div>

{% endblock %}

{% block js %}


    <script>
        $('#id_editer').on('click', function () {
            let old_pwd = $('#id_old_pwd').val()
            let new_pwd = $('#id_new_pwd').val()
            let confirm_pwd = $('#id_confirm_pwd').val()
            $.ajax({
                url: '/app01/set_password/',
                type: 'post',
                data: {
                    'old_pwd': old_pwd,
                    'new_pwd': new_pwd,
                    'confirm_pwd': confirm_pwd,
                    //'csrfmiddlewaretoken':{{ csrf_token }}
                },
                success: function (array) {
                    if (array.code === 1000) {
                        {#parent.location.href='/app01/login/'#}
                        //刷新当前url
                        alert('修改密码成功，重新登录')
                        window.location.reload()
                    } else {
                        $('#error').text(array.msg)
                    }

                }
            })

        });


        //前端渲染下载数。
        $('.down_file_class').click(function () {
            let old_number = $(this).prev().text()
            let new_number = parseInt(old_number) + 1
            $(this).prev().text(new_number)
            //用户下载自己的文件，下载数不会增加1
        })
    </script>

{% endblock %}